export const api_mixin = {
  methods: {
    /**统一接口返回消息处理*/
    async responseHandle(response, action = '操作') {
      let {status, message, result} = response
      let valid = status === 200

      return new Promise((resolve, reject) => {
        if (valid) {
          //this.$message({type: 'success', message: `{{action}}成功！`.format({action: action,})})
          resolve(result)
        } else {
          this.$message({
            type: 'error',
            dangerouslyUseHTMLString: true,
            message: `{{action}}失败！{{status}}：<br> {{message}}`.format({
              action: action,
              status: status || "",
              message: (message || "").replace(/\r\n/g, "<br>")
            })
          })
          reject()
        }
      }).catch(error => {
        reject(error)
      })
    }
  }
}
